package cn.edu.swufe.stu2025.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import org.w3c.dom.Text;

public class ScroingActivity extends AppCompatActivity {
    TextView score,score2;
    Button reset,add1,add2,add3;
    Button reset2,add1_2,add2_2,add3_2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_scroing);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        score=findViewById(R.id.score);
        score2=findViewById(R.id.score2);

        reset = findViewById(R.id.reset);
        reset.setOnClickListener((v)->{
            score.setText("0");
            score2.setText("0");
        });
    }
    public void click(View btn){
        Log.i("add","click1111");
        TextView score=findViewById(R.id.score);
        String s=(String)score.getText();
        int ints=Integer.parseInt(s);
        if(btn.getId()==R.id.add3){
            ints+=3;
        }
        else if (btn.getId()==R.id.add2){
            ints+=2;
        }
        else{
            ints+=1;
        }
        s=Integer.toString(ints);
        score.setText(s);
    }
    public void click2(View btn){
        Log.i("add","click2222");
        TextView score=findViewById(R.id.score2);
        String s=(String)score.getText();
        int ints=Integer.parseInt(s);
        if(btn.getId()==R.id.add3_2){
            ints+=3;
        }
        else if (btn.getId()==R.id.add2_2){
            ints+=2;
        }
        else{
            ints+=1;
        }
        s=Integer.toString(ints);
        score.setText(s);
    }

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        String scorea=score.getText().toString();
        String score=score2.getText().toString();

        outState.putString("teamA",scorea);

    }
}